package gdut.stream.middle;

import java.util.Arrays;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Stream;

public class MapTest {
    public static void main(String[] args) {
        Integer[] arr = {1, 2, 3, 4, 5};
//        map操作可以对流中的元素进行计算或者转换类型
        Stream<Integer> integerStream = Arrays.stream(arr);
        integerStream
                .map(new Function<Integer, Integer>() {
                    @Override
                    public Integer apply(Integer integer) {
//                对元素加100
                        return integer + 100;
                    }
                })
                .map(new Function<Integer, String>() {
                    @Override
                    public String apply(Integer integer) {
                        return integer.toString()+"变成字符串";
                    }
                })
                .forEach(new Consumer<String>() {
                    @Override
                    public void accept(String s) {
                        System.out.println(s);
                    }
                });
    }
}
